package com.automobile.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.automobile.domain.BeanBrandTypeCategory;
import com.automobile.domain.CarBrand;
import com.automobile.domain.CarType;
import com.automobile.domain.Category;
import com.automobile.service.CategoryService;

@Controller
@RequestMapping("/category")
public class CategoryController {
	
	@Autowired
	private CategoryService categoryService;
	
	@RequestMapping("/beanBTC")
	public @ResponseBody BeanBrandTypeCategory findCategory() {
		List<CarBrand> carbrands = null;
		List<CarType> carTypes = null;
		List<Category> categories = null;
		try {
			carbrands = categoryService.findCarBrandAll();
			carTypes = categoryService.findCarTypeAll();
			categories = categoryService.findCategoryAll();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new BeanBrandTypeCategory(categories, carbrands, carTypes);
	}

	@GetMapping("/brand")
    public @ResponseBody List<CarBrand> findBrandAll(){
	    return categoryService.findCarBrandAll();
    }
	
}
